using UnityEngine;

/// <summary>
/// 泛型单例基类
/// </summary>
/// <typeparam name="T"></typeparam>
public class SingletonBase<T> : MonoBehaviour where T : MonoBehaviour
{
    // 给外界提供一个访问的变量，让外界来访问唯一的该类所生产的对象
    private static T instance;

    // 不提供set，只提供get访问
    public static T Instance => instance;

    protected virtual void Awake()
    {
        instance = this as T;
    }

    protected virtual void OnDestroy()
    {
        instance = null;
    }
}